package com.admin.server.domain;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.admin.share.model.RolDTO;
import com.admin.share.model.UsuarioDTO;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
public class Rol {
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	@Persistent
	private String descripcion;
	@Persistent
	private Boolean haschildren;
	@Persistent
	private Boolean hasusers;
	@Persistent
	private Rol parent;
	@Persistent(mappedBy="parent")
	@Element(dependent = "true")
	private Set<Rol> children = new HashSet<Rol>();
	
	@Persistent
	private Set<Key> usuario_ids = new HashSet<Key>();
	
	public Key getKey() {
		return key;
	}	
	public String getDescripcion() {
		return descripcion;
	}
	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}
	public Boolean getHaschildren() {
		return haschildren;
	}
	public void setHaschildren(Boolean haschildren) {
		this.haschildren = haschildren;
	}
	public Boolean getHasusers() {
		return hasusers;
	}
	public void setHasusers(Boolean hasusers) {
		this.hasusers = hasusers;
	}
	public Rol getParent() {
		return parent;
	}	
	public Set<Rol> getChildren() {
		return children;
	}
	public void addChildren(Rol children) {
		this.children.add(children);
	}
	public Set<Key> getUsuario_ids() {
		return usuario_ids;
	}
	public void addUsuario_id(Key usuario_id) {
		this.usuario_ids.add(usuario_id);
	}
	public UsuarioDTO toUsuarioDTO() {
		UsuarioDTO userDTO = new UsuarioDTO();
		userDTO.setId(KeyFactory.keyToString(key));
		userDTO.setUsuario(descripcion);
		userDTO.setHaschildren(haschildren);
		userDTO.setHasusers(hasusers);
		
		return userDTO;
	}
	public RolDTO toDTO() {
		RolDTO rolDTO = new RolDTO();
		rolDTO.setUsuario(descripcion);
		rolDTO.setParent_id(KeyFactory.keyToString(key));
		return null;
	}
	
	

}
